<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="local" style="width: 600px;height: 400px;"></div>
    <div id="remote" style="width: 600px;height: 400px;"></div>
    <script src="js/trtc.js"></script>
    <script src="js/lib-generate-test-usersig.min.js"></script>
    <script>
        const SDKAPPID = 1400505489;
        const SECRETKEY = "0e2c317974537f488bed2c5327465524088219d9093326c860bfb2a38afc3dc9"

        const userId = parseInt(1000 * Math.random()).toString()
        const EXPIPETIME = 7 * 24 * 60 * 60;
        const generator = new LibGenerateTestUserSig(SDKAPPID, SECRETKEY, EXPIPETIME)
        const userSig = generator.genTestUserSig(userId)

        const client = TRTC.createClient({
            mode: 'rtc',
            sdkAppId: SDKAPPID,
            userId,
            userSig
        })
        let roomId = 0000001;
        client.join({
            roomId
        }).catch((error) => {
            console.error(error)
        }).then(() => {
            const localStream = TRTC.createStream({
                    userId,
                    audio: true,
                    video: true
                })
                // 初始化本地
            localStream.initialize().catch(error => {
                console.error(error)
            }).then(() => {
                localStream.play("local")
                    // 发布流
                client.publish(localStream).catch(error => {
                    console.error(error)
                }).then(() => {
                    console.log('发送成功')
                })
            })

        })


        // 订阅远端

        client.on('stream-added', (event) => {
            const remoteStream = event.stream;
            console.log(remoteStream.getId(), 11111)
            client.subscribe(remoteStream)
        })

        client.on('stream-subscribed', (event) => {
            const remoteStream = event.stream
            remoteStream.play("remote")
        })
    </script>
</body>

</html>